package com.anolesoft.twelvePlan.controller;

import cn.hutool.core.bean.BeanUtil;
import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.twelvePlan.dto.BasWorkhourCountDTO;
import com.anolesoft.twelvePlan.dto.GongDuanPlanDTO;
import com.anolesoft.twelvePlan.service.BasWorkhourCountService;
import com.anolesoft.twelvePlan.vo.BasWorkhourCountVO;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.PageData;
import com.anolesoft.yr.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zyq
 * @date 2022/7/1
 */
@RestController
@RequestMapping(value="/basWorkhourCount")
@Slf4j
public class BasWorkhourCountController {
    @Autowired
    private BasWorkhourCountService basWorkhourCountService;

    @GetMapping(value = "/query")
    public AjaxResult queryWorkHour(BasWorkhourCountVO basWorkhourCountVO){
        log.debug("basWorkhourCountVO: {}",basWorkhourCountVO);
        LoginUser loginUser = SecurityUtils.getLoginUser();
        basWorkhourCountVO.setFactoryId(loginUser.getFacCode());
        Integer pageSize = basWorkhourCountVO.getPageSize();
        Integer pageNo = basWorkhourCountVO.getPageNo();
        BasWorkhourCountDTO basWorkhourCountDTO = BeanUtil.copyProperties(basWorkhourCountVO, BasWorkhourCountDTO.class);
        log.debug("basWorkhourCountDTO: {}",basWorkhourCountDTO);
        PageData<List<BasWorkhourCountDTO>> pageData = this.basWorkhourCountService.queryWorkHour(basWorkhourCountDTO,pageNo,pageSize);
        List<BasWorkhourCountVO> basWorkhourCountVOS = pageData.getItems().stream()
                .map(t -> BeanUtil.copyProperties(t, BasWorkhourCountVO.class))
                .collect(Collectors.toList());
        PageResult pageResult = new PageResult(basWorkhourCountVOS, pageSize, pageNo, pageData.getTotal());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pageResult);
    }
}
